package io.qar.mq.producer;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RenProducerService {
    @Value("${qar.rocketmq.orderTopic}")
    private String orderTopic;
    @Value("${qar.rocketmq.payTopic}")
    private String payTopic;
    @Resource
    private RocketMQTemplate rocketMQTemplate;


    public void producersMessage(){
        Message<String> msg = MessageBuilder.withPayload("demo-000").build();
        rocketMQTemplate.send("demoTopic", msg);
    }

    /*
     * 发送订单消息
     */
    public SendResult sendOrder(String msgBody) {
        SendResult sendResult = rocketMQTemplate.syncSend(orderTopic, MessageBuilder.withPayload(msgBody).build());
        return sendResult;
    }

    /**
     * 发送支付信息
     */
    public void sendPay(String msgBody) {
        rocketMQTemplate.syncSend(payTopic, MessageBuilder.withPayload(msgBody).build());
    }
}